package com.learn.jdk.stream;

import java.util.ArrayList;
import java.util.Optional;

/**
 * Copyright: Copyright (c) 2020
 *
 * @ClassName: com.learn.jdk.stream.StreamTest1
 * @Description: 该类的功能描述
 * @version: v1.0.0
 * @author: lipan
 * @date: 2020/9/3 10:30
 * <p>
 * Modification History:
 * Date         Author          Version            Description
 * ------------------------------------------------------------
 * 2020/9/3      lipan          v1.0.0               修改原因
 */

public class StreamTest1 {


    public static void main(String[] args) {
        ArrayList<String> list=new ArrayList<>();

        list.add("123");

        list.add("31");

        list.add("222");


        //默认比较首为大小升序
//        list.stream().sorted().forEach(System.out::println);


        //定义升序
        list.stream().sorted((a,b)->{
            Integer num1 = Optional.ofNullable(a).map(str -> Integer.parseInt(str)).orElse(0);
            Integer num2= Optional.ofNullable(b).map(str -> Integer.parseInt(str)).orElse(0);
            return  num1.compareTo(num2);
        }).forEach(System.out::println);



        //检查是否有2开头的数字
        list.stream().filter(str->{
            if(str!=null){
                String trim = str.trim();
                if(trim.length()!=str.length()){
                    return false;
                }else{
                    for (int i = 0; i <str.length() ; i++) {
                        if(!Character.isDigit(str.charAt(i))){
                            return  false;
                        }
                    }
                    return true;
                }
            }else{
                return  false;
            }
        }).anyMatch(s->s.startsWith("2"));
    }
}
